{{/* Uniform 'sort_by' parameter between built-in Hugo and Hugo Blox Builder ones */}}
{{/* Input: 'sort_by' parameter (string) */}}
{{/* Output: fixed 'sort_by' parameter (string) */}}

{{/*
    Fix the 'sort_by' parameter, by adding "Params." as prefix if it is not a built-in Hugo parameter.
    Since Hugo Blox Builder parameters are all standardised to lowercase-underscore convention, we:
    - remove any leading ".": ".Date" is the same as "Date"
    - check the first letter:
        - if it is capitalized, then we have a built-in Hugo parameter, and we do nothing
        - otherwise, it is a custom Hugo Blox Builder parameter, and we add "Params." as prefix
    This logic should also be backward compatible, since "Params.my_param" is not modified.
*/}}

{{ $param := strings.TrimLeft "." . }}
{{/* Get first letter */}}
{{ $first := substr $param 0 }}
{{/* Check if it is lowercase */}}
{{ if eq $first (lower $first) }}
    {{/* Add 'Params.' prefix */}}
    {{ $param = printf "Params.%s" $param }}
{{ end }}

{{ return $param }}
